<html>
<head>
	<meta charset='utf-8' />
	<title>后台管理</title>
	<meta http-equiv="keywords" content="求职,招聘,房屋,出租,出售,求租,求购,宠物,二手,二手车,二手物品,旧货,寻物,寻人,出兑,外兑"> 
	<meta http-equiv="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息">  
	<meta name="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息"/>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#nav_bottom{width:98%;margin:0 auto}
			#content{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#nav_bottom{width:450px;margin:0 auto}
			#content{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		.info_item{color:#444;margin:15px 0;display:flex}
		.info_item > div:last-child{flex:1}
	</style>
</head>
<body style='padding:0;margin:0;background:#eee'>
<!-- 1 Content容器 -->
<div id='Content'>
	<!-- 3 内容区-->
	<div style='margin:10px 0;word-break:break-all;padding:10px;'>
		
		<div style='float:right;text-align:right' onclick='After_Admin_Exit()'>退出</div>
		
		<h2 style='text-align:center;'>后台管理-用户管理</h2>
		
		<!--搜索用户-->
		<div>
			<input type="text" id='search' />
			<button id='search_btn'>按id查找</button>
		</div>


		<div style='margin:10px auto'>
			用户选择：
			<select id='user_stat'>
				<option value="all">全部</option>
				<option value="1">正常</option>
				<option value="2">已封禁</option>
			</select>

			<span id='Refresh_Infinite_Fpage_Data'></span>
		</div><hr>


		<!--列表区-->
		<div id='info_list'>
		

		</div><!--列表区-->

			<!--div style='border-bottom:1px solid #ccc;padding:15px 0'>
				<div>用户名：2134　</div>
				<div>id：2134　创建时间：2134　最后登陆：2134</div>
				<div style='text-align:right;margin-top:15px'>
					<button onclick=jump_record_info('1')>用户发布记录</button>
					<button onclick=jump_record_login('1')>用户登陆记录</button>
					<button>封禁</button>
				</div>
			</div-->

		<div style='margin:30px auto;text-align:center;' id='fpage'></div>

	</div>	<!-- 3 内容区结束-->	
</div><!-- 1 Content容器结束 -->


<div style='height:50px'></div>



<!--底部导航容器-->
<div id='Nav_Bottom' style='position:fixed;bottom:0;width:100%;height:45px'>



</body>
</html>


<script src='./Public/jquery.js'></script>
<script src='./Public/fun.js'></script>
<script>

	Check_After_User_Cookie();	//检测登陆状态
	
	var priv_name = 'after_user';
	Priv_Check(priv_name,function(res){
		if(res != 'ok'){
			alert('没有权限!');
			//location.href = document.referrer;
			//exit;
		}
	});
	$(function(){

		//获取前台用户列表
		After_Get_Before_User_List();


		//刷新无限分页数据
		Refresh_Infinite_Fpage_Data(function(){
			sessionStorage.after_user_pnow = 1;
			After_Get_Before_User_List();
		});

		if(sessionStorage.search_uid){
			$('#search').val(sessionStorage.search_uid);
		}else{
			$('#search').val('');
		}

	});




	//加载底部导航栏
	Load_NavBottom('after');

	//跳转到信息记录
	function jump_record_info(uid){
		location.href='after_record_info.html?jump_type=1&uid='+uid;
	}

	//跳转到登陆记录
	function jump_record_login(uid){
		location.href='after_record_login.html?uid='+uid;
	}

	//初始化当前页
	if(!sessionStorage.after_user_pnow){
		sessionStorage.after_user_pnow = 1;
	}
	

	//初始化用户状态选择
	if(!sessionStorage.after_user_stat){
		sessionStorage.after_user_stat = $('#user_stat').find('option:checked').val();
	}else{
		$("#user_stat").find('option').each(function(i,o){
			if(o.value == sessionStorage.after_user_stat){
				o.selected=true;
			}
		});
	}
	$('#user_stat').change(function(){
		$("#info_list").html('');
		$("#fpage").html('');
		sessionStorage.after_user_stat = $('#user_stat').find('option:checked').val();
		sessionStorage.after_user_pnow = 1;	//重置当前页
		After_Get_Before_User_List();
	});

	//alert(sessionStorage.after_user_stat);


	$('#search_btn').click(function(){

		var search_val = parseInt($('#search').val().trim());
		if(search_val > 0){
			sessionStorage.search_uid = search_val;
		}else{
			sessionStorage.removeItem('search_uid');
		}
		//alert(sessionStorage.search_uid);
		After_Get_Before_User_List();
	});


	//获取前台用户列表
	function After_Get_Before_User_List(){
		var type='After_Get_Before_User_List';
		Token(type,function(token){
			if(sessionStorage.search_uid && sessionStorage.search_uid > 0){
				var data = {
						token:token,
						type:type,
						uid:sessionStorage.search_uid,
					};
			}else{
				var data = {
						token:token,
						type:type,
						pnow:sessionStorage.after_user_pnow,
						user_stat:sessionStorage.after_user_stat
					};
			}
			$.ajax({
				url:url,
				type:'post',
				data:data,
				success(res){
					//console.log(res);
					if(!/^{.*}$/.test(res)){
						alert('没有更多数据了!');
						$("#fpage a").last().remove();
						if(sessionStorage.after_user_pnow > 1){
							sessionStorage.after_user_pnow = sessionStorage.after_user_pnow-1;
						}
						return;
					}
					var data = JSON.parse(res);
					var info = data.data;
					var info_str = '';
					for(var i=0;i<info.length;i++){
						//alert(i);
						if(info[i].user_stat==1){
							var stat_str = "<button onclick='After_Change_Stat("+info[i].user_id+","+info[i].user_stat+")'>封禁</button>";
						}else{
							var stat_str = "<button style='color:red' onclick='After_Change_Stat("+info[i].user_id+","+info[i].user_stat+")'>解封</button>";
						}
						var ctime = StampToYmd(parseInt(info[i].user_ctime)*1000);
						var ltime = StampToYmd(parseInt(info[i].user_ltime)*1000);
						info_str += "<div style='border-bottom:1px solid #ccc;padding:15px 0'>";
						info_str += "<div>用户名："+info[i].user_name+"</div>";
						info_str += "<div>id："+info[i].user_id+"　创建时间："+ctime+"　最后登陆："+ltime+"</div>";
						info_str += "<div style='text-align:right;margin-top:15px'>";
						info_str += "<button onclick='jump_record_info("+info[i].user_id+")'>用户发布记录</button>　";
						info_str += "<button onclick='jump_record_login("+info[i].user_id+")'>用户登陆记录</button>　";
						info_str += stat_str;
						info_str += "</div>";
						info_str += "</div>";
					}
					$("#info_list").html(info_str);
					if(sessionStorage.after_user_pnow > 0 && res != 'err'){
						Fpage4(data.pnow,data.max_page,function(pnow){
							sessionStorage.after_user_pnow = pnow;
							After_Get_Before_User_List();
						},10,1); //往后续查60页，前后显3条

					}
				}
			});
		});
	}


	//前台用户封禁操作
	function After_Change_Stat(uid,stat){

		var priv_name = 'AfterUser_Prohibit';
		Priv_Check(priv_name,function(res){
			if(res != 'ok'){
				alert('没有权限!');
				//location.href = document.referrer;
				exit;
			}
		});

		if(!confirm('确认该操作?')){
			return;
		}

		var type='After_Change_User_Stat';
		Token(type,function(token){
			$.ajax({
				url:url,
				type:'post',
				data:{
					type:type,
					token:token,
					uid:uid,
					stat:stat
				},
				success(res){
					console.log(res);
					if(res == 'ok'){
						//After_Get_Before_User_List();
						location.reload(1);
					}
				}
			});
		});
	}


</script>

